﻿#include <string>
#include <iostream>

using namespace std;
#define INT_MIN (-2147483647 - 1)


class Solution 
{
public:
	int reverse(int x) 
	{
		long long tmp = x;
		bool negFlag = (x < 0 ? true : false);
		string numStr = "";

		tmp = std::llabs(x);
		while (tmp != 0)
		{
			numStr.push_back((char)('0' + tmp % 10));
			tmp = tmp / 10;
		}
		numStr.reserve();
		tmp = std::atoll(numStr.c_str());
		if (negFlag)
		{
			tmp = -tmp;
		}
		if (isOverflow(tmp))
		{
			return 0;
		}
		return (int)tmp;
	}
private:
	const long long int min = INT_MIN;
	const long long int max = 2147483647;

	bool isOverflow(long long x)
	{
		if (x<min || x>max)
		{
			return true;
		}
		return false;
	}
};

int main()
{
	Solution s;
	cout << s.reverse(-123) << endl;
	return 0;
}